package shiftsservice;

import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.microedition.xml.rpc.Operation;
import javax.microedition.xml.rpc.Type;
import javax.microedition.xml.rpc.ComplexType;
import javax.microedition.xml.rpc.Element;

public class ShiftsService_Stub implements ShiftsService, javax.xml.rpc.Stub {
    
    private String[] _propertyNames;
    private Object[] _propertyValues;
    
    public ShiftsService_Stub() {
        _propertyNames = new String[] { ENDPOINT_ADDRESS_PROPERTY };
        _propertyValues = new Object[] { "http://localhost:1121/RetrieveShift/ShiftsService.asmx" };
    }
    
    public void _setProperty( String name, Object value ) {
        int size = _propertyNames.length;
        for (int i = 0; i < size; ++i) {
            if( _propertyNames[i].equals( name )) {
                _propertyValues[i] = value;
                return;
            }
        }
        String[] newPropNames = new String[size + 1];
        System.arraycopy(_propertyNames, 0, newPropNames, 0, size);
        _propertyNames = newPropNames;
        Object[] newPropValues = new Object[size + 1];
        System.arraycopy(_propertyValues, 0, newPropValues, 0, size);
        _propertyValues = newPropValues;
        
        _propertyNames[size] = name;
        _propertyValues[size] = value;
    }
    
    public Object _getProperty(String name) {
        for (int i = 0; i < _propertyNames.length; ++i) {
            if (_propertyNames[i].equals(name)) {
                return _propertyValues[i];
            }
        }
        if (ENDPOINT_ADDRESS_PROPERTY.equals(name) || USERNAME_PROPERTY.equals(name) || PASSWORD_PROPERTY.equals(name)) {
            return null;
        }
        if (SESSION_MAINTAIN_PROPERTY.equals(name)) {
            return new Boolean(false);
        }
        throw new JAXRPCException("Stub does not recognize property: " + name);
    }
    
    protected void _prepOperation(Operation op) {
        for (int i = 0; i < _propertyNames.length; ++i) {
            op.setProperty(_propertyNames[i], _propertyValues[i].toString());
        }
    }
    
    public Shift getMyNightShift(String userName) throws java.rmi.RemoteException {
        Object inputObject[] = new Object[] {
            userName
        };
        
        Operation op = Operation.newInstance( _qname_operation_getMyNightShift, _type_getMyNightShift, _type_getMyNightShiftResponse );
        _prepOperation( op );
        op.setProperty( Operation.SOAPACTION_URI_PROPERTY, "http://microsoft.com/webservices/getMyNightShift" );
        Object resultObj;
        try {
            resultObj = op.invoke( inputObject );
        } catch( JAXRPCException e ) {
            Throwable cause = e.getLinkedCause();
            if( cause instanceof java.rmi.RemoteException ) {
                throw (java.rmi.RemoteException) cause;
            }
            throw e;
        }
        
        return Shift_fromObject((Object[])((Object[]) resultObj)[0]);
    }
    
    private static Shift Shift_fromObject( Object obj[] ) {
        if(obj == null) return null;
        Shift result = new Shift();
        result.setMyShiftType((String )obj[0]);
        return result;
    }
    
    protected static final QName _qname_operation_getMyNightShift = new QName( "http://microsoft.com/webservices/", "getMyNightShift" );
    protected static final QName _qname_getMyNightShift = new QName( "http://microsoft.com/webservices/", "getMyNightShift" );
    protected static final QName _qname_getMyNightShiftResponse = new QName( "http://microsoft.com/webservices/", "getMyNightShiftResponse" );
    protected static final Element _type_getMyNightShift;
    protected static final Element _type_getMyNightShiftResponse;
    
    static {
        _type_getMyNightShift = new Element( _qname_getMyNightShift, _complexType( new Element[] {
            new Element( new QName( "http://microsoft.com/webservices/", "userName" ), Type.STRING, 0, 1, false )}), 1, 1, false );
        _type_getMyNightShiftResponse = new Element( _qname_getMyNightShiftResponse, _complexType( new Element[] {
            new Element( new QName( "http://microsoft.com/webservices/", "getMyNightShiftResult" ), _complexType( new Element[] {
                new Element( new QName( "http://microsoft.com/webservices/", "MyShiftType" ), Type.STRING, 0, 1, false )}))}), 1, 1, false );
    }
    
    private static ComplexType _complexType( Element[] elements ) {
        ComplexType result = new ComplexType();
        result.elements = elements;
        return result;
    }
}
